﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MidSoft.Sys
{
    public partial class RoleUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int RolesId = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(RolesId);
                }
            }
        }

        private void ShowInfo(int RolesId)
        {
            ChinaSoft.BLL.BLL_tb_MidSoft_Roles bll = new ChinaSoft.BLL.BLL_tb_MidSoft_Roles();
            ChinaSoft.Model.Model_tb_MidSoft_Roles model = bll.GetModel(RolesId);
            this.txtRoleName.Text = model.RoleName;
        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            int RoleId = ChinaSoft.Common.Input.SetInt(Request.Params["id"]);
            if (this.txtRoleName.Text.Trim().Length == 0)
            {
                strErr += "角色名不能为空！\\n";
            }

            if (strErr != "")
            {
                Maticsoft.Common.MessageBox.Show(this, strErr);
                return;
            }
            string RoleName = this.txtRoleName.Text;

            ChinaSoft.BLL.BLL_tb_MidSoft_Roles bll = new ChinaSoft.BLL.BLL_tb_MidSoft_Roles();
            ChinaSoft.Model.Model_tb_MidSoft_Roles model = bll.GetModel(RoleId);
            model.RoleName = RoleName;
            bll.Update(model);

            #region 添加日志
            ChinaSoft.Model.Model_tb_MidSoft_log modelLog = new ChinaSoft.Model.Model_tb_MidSoft_log();
            ChinaSoft.BLL.BLL_tb_MidSoft_log bllLog = new ChinaSoft.BLL.BLL_tb_MidSoft_log();
            modelLog.userAccount = "";
            if (Session["UserAccount"] != null && Session["UserAccount"].ToString() != "")
                modelLog.userAccount = Session["UserAccount"].ToString();
            modelLog.userName = "";
            if (Session["UserName"] != null && Session["UserName"].ToString() != "")
                modelLog.userName = Session["UserName"].ToString();
            modelLog.description = "角色信息修改,RoleId=" + RoleId + ",RoleName=" + RoleName;
            modelLog.LogType = 2;
            modelLog.CreateTime = DateTime.Now;
            bllLog.Add(modelLog);
            #endregion
            Response.Write("<script>alert('成功！');top.window.parent.frames.item('workspace').location.reload();window.parent.$('#DivSysiframe').dialog(\"close\");</script>");
        }
    }
}